package com.crm.controller;


import com.crm.base.ContractPageResponse;

import com.crm.base.ResponseResult;
import com.crm.domain.entity.Contract;
import com.crm.domain.entity.ContractParam;
import com.crm.mapper.ContractMapper;
import com.crm.service.ContractService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;

import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;

@RestController
@Api("合同管理")
@RequiredArgsConstructor
public class ContractController {


    private final ContractService contractService;

    private final ContractMapper contractMapper;

    @GetMapping("/contract/list")
    @ApiOperation("合同分页查询")
    public  ContractPageResponse<Contract> listContract(ContractParam conreactParam,
                                                @RequestParam(value = "[beginCreateTime]:", required = false)
                                                  @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate beginCreateTime,
                                                @RequestParam(value = "[endCreateTime]:", required = false)
                                                  @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate endCreateTime) {
        ContractPageResponse<Contract> list = contractService.list(conreactParam, beginCreateTime, endCreateTime);
        return list;
    }



    @GetMapping("/contract/{id}")
    @ApiOperation("合同详情")
    public ResponseResult ContractParticulars(@PathVariable Integer id){
        Contract byId = contractMapper.selectById(id);
        return ResponseResult.success(byId);
    }

    @GetMapping("/contract/detail/{id}")
    @ApiOperation("根据id查询")
    public ResponseResult ContractId(@PathVariable Integer id){
        Contract byId = contractMapper.selectById(id);
        return ResponseResult.success(byId);
    }

    @PutMapping("/contract")
    @ApiOperation("合同修改")
    public ResponseResult ContractModification(@RequestBody Contract contract){
        contractMapper.update(contract,null);
        return ResponseResult.success();
    }


    @PostMapping("/common/upload")
    @ApiOperation("文件上传")
    public ResponseResult Upload(){

        return ResponseResult.success();
    }



}
